
package uk.addie.mp3fixer.visitors;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.logging.Level;

import uk.addie.mp3fixer.MP3Fixer;
import uk.addie.mp3fixer.MP3Handle;

public class RenameLikeId3 extends AbstractVisitor {
    @Override protected String buttonName() {
        return "Rename all files";
    }

    @Override protected void modifyMp3(final MP3Handle mp3, final Path file) {
        final StringBuilder newName = mp3.canonicalName();
        try {
            Files.move(file, file.getParent().resolve(newName.toString()), StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            MP3Fixer.LOG.log(Level.SEVERE, "Can't move file", e);
        }
    }
}
